home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.std.c
- Path: dd.chalmers.se!news.chalmers.se!sunic!EU.net!howland.reston.ans.net!cs.utexas.edu!news.unt.edu!news.oc.com!pssparc2.oc.com!lfw
- From: lfw@pssparc2.oc.com (Larry Weiss)
- Subject: Re: allocating 0 bytes with malloc()?
- Message-ID: <lfw.762560906@pssparc2.oc.com>
- Sender: usenet@ra.oc.com
- Organization: OpenConnect Systems, Dallas, TX
- References: <jeffroCL24Ks.3qr@netcom.com> <KARL.94Feb13142514@ursa-major.spdcc.com> <761528644snz@genesis.demon.co.uk> <1994Feb21.112831.1594@inmos.co.uk> <2kvpth$56i@bb29c.mdd.comm.mot.com>
- Distribution: na
- Date: Tue, 1 Mar 1994 22:28:26 GMT
- Lines: 44
- Xref: dd.chalmers.se comp.lang.c:10479 comp.std.c:1140
-
- mitchell@mdd.comm.mot.com (Bill Mitchell) writes:
-
- >in comp.lang.c, conor@inmos.co.uk (Conor O'Neill) said:
- >>However, unfortunately the issue is now moot. ANSI C says that
- >>malloc(0) is one of those funny little wrinkles, and as such,
- >>programmers must code around it.
-
- >Where? Section 4.10.3.3 says, in its entirety:
- > 4.10.3.3 The malloc Function
- >
- > Synopsis
- > #include <stdlib.h>
- > void *malloc(size_t size);
- >
- > Description
- > The malloc function allocates space for an object whose size is
- > specified by size and whose value is indeterminate.
- >
- > Returns
- > The malloc function returns either a null pointer or a pointer to
- > the allocated space.
-
- There is additional language in the enclosing section 7.10.3 (ISO numbering,
- your 4.10.3):
-
- 7.10.3 Memory management functions
-
- The order and contiguity of storage allocated by sucessive calls to the
- calloc, malloc, and realloc functions is unspecified. The pointer returned
- if the allocation succeeds is suitably aligned so that it may be assigned
- to a pointer to any type of object and then used to access such an object
- or an array of such objects in the space allocated (until the space is
- explicitly freed or reallocated). Each such allocation shall yield a
- pointer to an object disjoint from any other object. The pointer returned
- points to the start (lowest byte address) of the allocated space. If
- the space cannot be allocated, a null pointer is returned. If the size
- of the space requested is zero, the behavior is implementation-defined;
- the value returned shall be either a null pointer or a unique pointer.
- The value of a pointer that refers to freed space is indeterminate.
-
- --
- Larry Weiss, lfw@oc.com
- 214/888-0471
-